package com.dk.service.impl;


import com.dk.mapper.PlayerDataMapper;
import com.dk.mapper.RelaxationMapper;
import com.dk.pojo.playerData.PlayerDataVO;
import com.dk.pojo.relaxation.Relaxation;
import com.dk.pojo.relaxation.RelaxationExample;
import com.dk.service.RelaxationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RelaxationServiceImpl implements RelaxationService {
    @Autowired
    private RelaxationMapper relaxationMapper;
    @Autowired
    private PlayerDataMapper playerDataMapper;

    @Override
    public PageInfo<Relaxation> show(Relaxation relaxation,Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        RelaxationExample example = new RelaxationExample(Relaxation.class);
        RelaxationExample.Criteria criteria = example.createCriteria();
        //官方给的各种网址
        criteria.andGameIdEqualTo(0);
        //按照名字查找
        criteria.andRelaxationNameLike("%"+relaxation.getRelaxationName()+"%");
        List<Relaxation> list = relaxationMapper.selectByExample(example);
        PageInfo<Relaxation> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public boolean addInfo(Relaxation relaxation,Integer playerAccount) {
        //根据登录用户的信息去查询其对应系统，根据对应系统添加其自己添加的网址
        PlayerDataVO playerDataVO = playerDataMapper.seleteByAccountPlayer(playerAccount);
        relaxation.setGameId(playerDataVO.getGames());
        return relaxationMapper.insert(relaxation) > 0;
    }

    @Override
    public Relaxation toUpdatet(Integer id) {
        return relaxationMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean updateInfo(Relaxation relaxation,Integer playerAccount) {
        //根据登录用户的信息去查询其对应系统，根据对应系统添加其自己添加的网址
        PlayerDataVO playerDataVO = playerDataMapper.seleteByAccountPlayer(playerAccount);
        relaxation.setGameId(playerDataVO.getGames());
        return relaxationMapper.updateByPrimaryKey(relaxation) > 0;
    }

    @Override
    public boolean deleteInfo(Integer id) {
        return relaxationMapper.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public PageInfo<Relaxation> showByWork(Integer playerAccount, Relaxation relaxation, Integer pageNumber, Integer pageSize) {
        //根据登录用户的信息去查询其对应系统，根据对应系统查找其自己添加的网址
        PlayerDataVO playerDataVO = playerDataMapper.seleteByAccountPlayer(playerAccount);
        PageHelper.startPage(pageNumber,pageSize);
        RelaxationExample example = new RelaxationExample(Relaxation.class);
        RelaxationExample.Criteria criteria = example.createCriteria();
        //官方给的各种网址
        criteria.andGameIdEqualTo(playerDataVO.getGames());
        //按照名字查找
        criteria.andRelaxationNameLike("%"+relaxation.getRelaxationName()+"%");
        List<Relaxation> list = relaxationMapper.selectByExample(example);
        PageInfo<Relaxation> page = new PageInfo<>(list);
        return page;
    }
}
